home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Format CD 51
/
Amiga Format CD51 (2000-03-10)(Future Publishing)(GB)[!][issue 2000-04].iso
/
-in_the_mag-
/
program_perfection
/
toolbar_demo
/
toolbar_demo.c
< prev
next >
Wrap
C/C++ Source or Header
|
2000-02-16
|
6KB
|
228 lines
/*
* A quick demo for Reaction SpeedBar class
* Richard Drummond 3/2/2000
*
*/
#include <exec/types.h>
#include <intuition/intuition.h>
#include <proto/intuition.h>
#include <proto/exec.h>
#include <proto/dos.h>
#define ALL_REACTION_CLASSES
#define ALL_REACTION_MACROS
#include <reaction/reaction.h>
#define GID_QUIT 1L
struct SpeedButton
{
UBYTE ID;
BOOL Disabled;
CONST_STRPTR ImageName;
};
enum
{
SBID_OPEN_BUTTON,
SBID_COPY_BUTTON,
SBID_SEARCH_BUTTON,
SBID_GOTO_BUTTON
};
CONST struct SpeedButton ButtonData[] = {
{ SBID_OPEN_BUTTON, FALSE, "PROGDIR:load.ilbm" },
{ SBID_COPY_BUTTON, TRUE, "PROGDIR:copy.ilbm" },
{ SBID_SEARCH_BUTTON, FALSE, "PROGDIR:search.ilbm" },
{ SBID_GOTO_BUTTON, FALSE, "PROGDIR:goto.ilbm" },
{ 0, FALSE, NULL }
};
/*
* CreateButtons()
*
* Allocate the buttons for our speed bar
*/
BOOL
CreateButtons( struct SpeedButton *button, struct List *list, struct Screen *screen )
{
/* struct SpeedButton *button; */
NewList( list );
for( /* button = &(ButtonData[0]) */ ; button->ImageName; button++ )
{
struct Object *image;
if( image = BitMapObject,
BITMAP_SourceFile, button->ImageName,
BITMAP_Screen, screen,
BitMapEnd )
{
struct Node *node;
if( node = AllocSpeedButtonNode( (BYTE) -button->ID,
SBNA_Image, image,
SBNA_Disabled, button->Disabled,
SBNA_Spacing, -1,
SBNA_Highlight, SBH_RECESS,
TAG_DONE ) )
{
/* Okay - now add it to speedbar list */
Enqueue( list, node );
}
}
} /* for */
/* We really need some cleanup here */
return TRUE;
}
/*
* FreeButtons()
*
* Deallocate our speedbar buttons
*/
VOID
FreeButtons( struct List *list )
{
struct Node *node, *next;
/* get first in list */
node = list->lh_Head;
while( next = node->ln_Succ )
{
Object *image;
/* get a pointer to this object's image */
GetSpeedButtonNodeAttrs( node, SBNA_Image, &image, TAG_DONE );
/* free it */
if(image)
DisposeObject(image);
/* free the button itself */
FreeSpeedButtonNode( node );
node = next;
}
NewList( list );
}
int main(void)
{
struct Screen *screen;
struct List speedbar_list;
Object *win_obj;
/* intialize */
screen = LockPubScreen( NULL );
CreateButtons( &ButtonData[0], &speedbar_list, screen );
/* make the window object */
if( win_obj = WindowObject,
WA_Title, "Speedbar Demo",
WA_Activate, TRUE,
WA_DepthGadget, TRUE,
WA_DragBar, TRUE,
WA_CloseGadget, TRUE,
WA_SizeGadget, TRUE,
WA_SizeBBottom, TRUE,
WINDOW_Position, WPOS_CENTERMOUSE,
WINDOW_ParentGroup, VGroupObject,
LAYOUT_SpaceOuter, TRUE,
LAYOUT_DeferLayout, TRUE,
/* Speedbar */
LAYOUT_AddChild, SpeedBarObject,
SPEEDBAR_Orientation, SBORIENT_HORIZ,
SPEEDBAR_Buttons, &speedbar_list,
SPEEDBAR_BevelStyle, BVS_NONE,
SpeedBarEnd,
CHILD_NominalSize,TRUE,
/* Quit button */
LAYOUT_AddChild, ButtonObject,
GA_ID, GID_QUIT,
GA_RelVerify, TRUE,
GA_Text,"_Quit",
ButtonEnd,
CHILD_WeightedHeight, 0,
EndGroup,
EndWindow )
{
struct Window *window; /* the actual Intuition window */
if( window = (struct Window *) RA_OpenWindow( win_obj ) )
{
ULONG wait, signal;
ULONG done = FALSE;
ULONG result;
UWORD code;
/* Get the window's signal bit */
GetAttr( WINDOW_SigMask, win_obj, &signal );
/* Even loop */
while( !done )
{
wait = Wait( signal | SIGBREAKF_CTRL_C );
if ( wait & SIGBREAKF_CTRL_C )
{
done = TRUE;
}
else
{
while( ( result = RA_HandleInput( win_obj, &code ) ) != WMHI_LASTMSG )
{
switch( result & WMHI_CLASSMASK )
{
case WMHI_CLOSEWINDOW:
done = TRUE;
break;
case WMHI_GADGETUP:
switch (result & WMHI_GADGETMASK)
{
case GID_QUIT:
done = TRUE;
break;
}
break;
}
}
} /* else */
} /* end event loop */
} /* end if */
DisposeObject( win_obj );
}
/* Cleanup */
FreeButtons( &speedbar_list );
UnlockPubScreen( NULL, screen );
return 0L;
}